import React, {ChangeEvent, FormEvent, FormEventHandler} from "react";

class Login2 extends React.Component<any, any> {

    state = {
        userName: '',
        password: ''
    }

    login = (event: FormEvent) => {
        event.preventDefault()
        alert(`用户名：${this.state.userName}密码：${this.state.password}`);
    }

    saveUserName = (event: any) => {
        this.setState({userName: event.target.value})
    }

    savePassword = (event: any) => {
        this.setState({password: event.target.value})
    }

    render() {
        return (
            <>
                <form onSubmit={this.login}>
                    用户名：<input onChange={this.saveUserName} type="text" placeholder="输入用户名"/>
                    密码：<input onChange={this.savePassword} type="password" placeholder="输入密码"/>
                    <button>登录</button>
                </form>
            </>
        );
    }
}

export default Login2